import { Component } from '@angular/core';
import {HttpService} from '../provider.service';
import sd from 'silly-datetime'

@Component({
  selector: 'app-tab2',
  templateUrl: 'tab2.page.html',
  styleUrls: ['tab2.page.scss']
})
export class Tab2Page {
  rowsList:any;
  getSelectedValue:any;
  someItems:any;
  strDate:any;
  endDate:any;
  columns = [
    // 将第一列（在我的表格中指向“项目名称”这一列）固定
    { prop: 'dt', name: '时间', frozenLeft: true },
    { prop: 'hq', name: '流量' }, 
    { prop: 'rawq', name: '正向流量' },
    { prop: 'q', name: '反向流量' },
    { prop: 'avgv1', name: '流速' },
  ]
  constructor(private httpService:HttpService) {
    this.getSelectedValue='6000';
    this.strDate=sd.format(new Date(new Date().getTime() - 24*60*60*1000), 'YYYY/MM/DD HH:mm:ss');
    this.endDate=sd.format(new Date(), 'YYYY/MM/DD HH:mm:ss');
    this.rowsList=[
      {
        'dt':'2019/01/01',
        'hq':300,
        'rawq':100,
        'q':522,
        'avgv1':100
      }
    ]
    this.someItems=[
      {
        'stationid':0,
        'stationState':0,
        'stationName':'a站',
        'currentFlow':500
      },
      {
        'stationid':1,
        'stationState':0,
        'stationName':'b站',
        'currentFlow':500
      },
      {
        'stationid':1,
        'stationState':0,
        'stationName':'c站',
        'currentFlow':600
      }
    ]
  }
  getStationData(){
    this.httpService.post("index/getStatData",null).then(res=>{
      if(res.success){
        this.someItems = res;
      }
      
    });
  }
  getApiData(obj){
    
    this.httpService.post("query/getDataListBySTCD",obj).then(res=>{
      console.log(res)
      var arr=[];
      if(res.success&&res.length>0){
        res.forEach(item=>{
          var time=sd.format(item.dt, 'YYYY/MM/DD HH:mm:ss')
          arr.push({
            'dt':time,
            'hq':(item.q+item.rawq),
            'q':item.q,
            'rawq':item.rawq,
            'avgv1':item.avgv1
          })
        })
        this.rowsList=arr;
      }
    });
  }
  getDealerName(){

  };
  search(){
    let data={
      'STCD':this.getSelectedValue,
      'strtDte':this.strDate,
      'endDte':this.endDate
    }
    this.getApiData(data)
  };
  ionViewWillEnter(){
    let data={
      'STCD':this.getSelectedValue,
      'strtDte':this.strDate,
      'endDte':this.endDate
    }
    this.getStationData()
    this.getApiData(data)
  }
}
